<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['id']){
		$this->session('listid',intval($_RQ['id']));
	}
	if(!$this->session('listid')){
		exi('请由答辩项目进入售后记录！','error');
	}
	$params['listid']=$this->session('listid');
	if($_RQ['title']){
		$params2=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
		$xueshengs=pdo_getall('jy_yxw_xuesheng',$params2,array('id'),'id');
		if($xueshengs){
			$xueshengs=array_keys($xueshengs);
		}else{
			$xueshengs=-1;
		}
		$params['xueshengid']=$xueshengs;
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('jy_yxw_dabian_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$info=pdo_get('jy_yxw_dabian_list',array('id'=>$this->session('listid'),'uniacid'=>$_SESSION['uniacid']));
		foreach($list as &$item){
			$item['member']=$this->model('xuesheng')->member_show($item['xueshengid']);
			$item['classid']=$info['classid'];
			$item['title']=$info['title'];
			$item['workerid']=$info['workerid'];
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'售后成绩记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'title','title'=>'答辩标题','type'=>'string'),
			array('name'=>'classid','title'=>'所属售后群','type'=>'select','options'=>'class'),
			array('type'=>'string','title'=>'总项目成绩','name'=>'jdfen'),
			array('type'=>'string','title'=>'总考勤成绩','name'=>'ksfen'),
			array('type'=>'string','title'=>'总违纪成绩','name'=>'bsfen'),
			array('type'=>'string','title'=>'总成绩','name'=>'allfen'),
			array('type'=>'string','title'=>'总评分','name'=>'fenstar'),
			array('type'=>'radio','title'=>'评级','name'=>'fenji','options'=>'fenji'),
			array('name'=>'workerid','title'=>'评分员工','type'=>'select','options'=>'workers'),
			//array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','action'=>'/xuesheng.chengji_log/edit/','title'=>'编辑成绩'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>10,'title'=>'售后姓名','type'=>'string'),
		),
	);
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['workers']=$this->getall('worker',array('role'=>array(9,10,11,12,13),'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['htmls']=$htmls;
	$return['fenji']=$this->danan_key;
	exi($return);
}
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array(
			'jdfen'=>intval($post['jdfen']),
			'ksfen'=>intval($post['ksfen']),
			'bsfen'=>intval($post['bsfen']),
			'allfen'=>intval($post['allfen']),
			'fenstar'=>intval($post['fenstar']),
			'fenji'=>intval($post['fenji']),
		);
		pdo_update('jy_yxw_dabian_log',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('操作成功！','','goback');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_dabian_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择售后答辩','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'售后答辩成绩',
	);
	$htmls['edit']=array(
			array('type'=>'string','title'=>'项目成绩','name'=>'jdfen'),
			array('type'=>'string','title'=>'总考勤成绩','name'=>'ksfen'),
			array('type'=>'string','title'=>'总违纪成绩','name'=>'bsfen'),
			array('type'=>'string','title'=>'总成绩','name'=>'allfen'),
			array('type'=>'string','title'=>'总评分','name'=>'fenstar'),
			array('type'=>'radio','title'=>'评级','name'=>'fenji','options'=>'fenji'),
	);
	$return['fenji']=$this->danan_key;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['id']){
		$this->session('listid',intval($_RQ['id']));
	}
	if(!$this->session('listid')){
		exi('请由答辩项目进入售后记录！','error');
	}
	$params['listid']=$this->session('listid');
	$list=pdo_getall('jy_yxw_dabian_log',$params,$fields);
	if($list){
		$info=pdo_get('jy_yxw_dabian_list',array('id'=>$this->session('listid'),'uniacid'=>$_SESSION['uniacid']));
		foreach($list as &$item){
			$item['title']=pdo_getcolumn('jy_yxw_xuesheng',array('id'=>$item['xueshengid'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['fenji']=$this->danan_key[$item['fenji']];
		}
	}
	$header=array(
		'title'=>'售后姓名',
		'sn'=>'售后编号',
		'class'=>'售后群',
		'jdfen'=>'项目成绩',
		'ksfen'=>'总考勤成绩',
		'bsfen'=>'总违纪成绩',
		'allfen'=>'总成绩',
		'fenstar'=>'总评分',
		'worker'=>'评分员工',
		'qianming'=>'售后签名',
	);
	model('core/tools')->export2excel($header,$list,'成绩表');
}